//
//  BaseNavController.swift
//  HJWeibo
//
//  Created by mac on 16/1/20.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class BaseNavController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        //重新设置右滑返回的手势代理
        self.interactivePopGestureRecognizer?.delegate = self
    }

    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        //调用super的方法
        //设置底部tabbar的隐藏
        if childViewControllers.count != 0 {
            
            viewController.hidesBottomBarWhenPushed = true
            
            let btn = UIButton(title: "返回", fontSize: 14, color: UIColor.darkGrayColor(), backImageName: nil, imageName: "navigationbar_back_withtext")
            btn.addTarget(self, action: "back", forControlEvents: .TouchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        }
        //这句代码执行完毕后，才会真正的添加到导航视图控制器中成为子视图
        super.pushViewController(viewController, animated: true)
    }
    
    //实现 按钮方法
    @objc private func back() {
        //在本类中，self就是导航视图控制器
        popViewControllerAnimated(true)
    }
    
    
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        print(childViewControllers.count)
        
//        if childViewControllers.count > 1 {
//            return true
//        }
//        
//        return false
        return childViewControllers.count > 1
    
    }
    
}
